<!DOCTYPE html>
<html>
<head>
  <title>Physics Diagram of Ring and Beads</title>
</head>
<body>
  <canvas id="physicsCanvas" width="500" height="480"></canvas>
  <script>
    const canvas = document.getElementById('physicsCanvas');
    const ctx = canvas.getContext('2d');

    // --- Style and Parameters ---
    const cx = 230;
    const cy = 240;
    const innerRadius = 150;
    const pipeThickness = 15;
    const outerRadius = innerRadius + pipeThickness;
    const beadRadius = 9;
    const arrowLength = 80;
    const arrowHeadSize = 10;
    const v0_subscript = '\u2080';

    ctx.strokeStyle = 'black';
    ctx.fillStyle = 'black';
    ctx.lineWidth = 2.5;

    // --- Helper function to draw an arrow with a filled head ---
    function drawArrow(x1, y1, x2, y2, headLength) {
      ctx.save();
      ctx.lineWidth = 2;
      ctx.fillStyle = 'black';
      ctx.strokeStyle = 'black';

      const dx = x2 - x1;
      const dy = y2 - y1;
      const angle = Math.atan2(dy, dx);

      // Draw the arrow line
      ctx.beginPath();
      ctx.moveTo(x1, y1);
      ctx.lineTo(x2, y2);
      ctx.stroke();

      // Draw the filled arrowhead
      ctx.beginPath();
      ctx.moveTo(x2, y2);
      ctx.lineTo(x2 - headLength * Math.cos(angle - Math.PI / 6), y2 - headLength * Math.sin(angle - Math.PI / 6));
      ctx.lineTo(x2 - headLength * Math.cos(angle + Math.PI / 6), y2 - headLength * Math.sin(angle + Math.PI / 6));
      ctx.closePath();
      ctx.fill();
      ctx.restore();
    }

    // --- Draw the Ring (Pipe) ---
    // Outer circle
    ctx.beginPath();
    ctx.arc(cx, cy, outerRadius, 0, 2 * Math.PI);
    ctx.stroke();
    // Inner circle
    ctx.beginPath();
    ctx.arc(cx, cy, innerRadius, 0, 2 * Math.PI);
    ctx.stroke();

    // --- Draw the Center Point ---
    ctx.beginPath();
    ctx.arc(cx, cy, 4, 0, 2 * Math.PI);
    ctx.fill();

    // --- Draw the Dashed Diameter AB ---
    ctx.save();
    ctx.setLineDash([7, 5]);
    ctx.lineWidth = 1.5;
    ctx.beginPath();
    ctx.moveTo(cx, cy - innerRadius);
    ctx.lineTo(cx, cy + innerRadius);
    ctx.stroke();
    ctx.restore();

    // --- Draw the Beads ---
    const topBeadY = cy - innerRadius;
    const bottomBeadY = cy + innerRadius;
    const beadColor = '#333333';

    // Top bead
    ctx.beginPath();
    ctx.arc(cx, topBeadY, beadRadius, 0, 2 * Math.PI);
    ctx.fillStyle = beadColor;
    ctx.fill();
    ctx.strokeStyle = 'black';
    ctx.lineWidth = 1;
    ctx.stroke();

    // Bottom bead
    ctx.beginPath();
    ctx.arc(cx, bottomBeadY, beadRadius, 0, 2 * Math.PI);
    ctx.fill();
    ctx.stroke();
    
    // Reset fill style
    ctx.fillStyle = 'black';

    // --- Draw the Velocity Vectors ---
    // Top vector
    drawArrow(cx, topBeadY, cx + arrowLength, topBeadY, arrowHeadSize);
    // Bottom vector
    drawArrow(cx, bottomBeadY, cx + arrowLength, bottomBeadY, arrowHeadSize);

    // --- Add Labels ---
    ctx.font = 'italic 28px Times New Roman';
    ctx.textAlign = 'center';
    ctx.textBaseline = 'middle';

    // Label M
    ctx.fillText('M', cx - outerRadius - 40, cy);

    // Label m (top)
    ctx.fillText('m', cx, topBeadY - 28);

    // Label m (bottom)
    ctx.fillText('m', cx, bottomBeadY + 28);

    // Label A
    ctx.fillText('A', cx - 35, topBeadY + 45);

    // Label B
    ctx.fillText('B', cx - 35, bottomBeadY - 45);
    
    // Label v₀ (top)
    ctx.fillText('v' + v0_subscript, cx + arrowLength + 30, topBeadY);

    // Label v₀ (bottom)
    ctx.fillText('v' + v0_subscript, cx + arrowLength + 30, bottomBeadY);

  </script>
</body>
</html>